<?php
namespace App\Libraries\Decorator\Product;


use App\Libraries\Decorator\DecoratorInterface\ModelDecorator;
use App\Libraries\Tools\MLM;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class VIPDecorator implements ModelDecorator
{

    public function before(){
        //todo
    }

    public function after(&$data){
        if(!is_array($data)){
            $data = json_decode(json_encode($data), true);
        }
        if (isset($data['money'])) {
            // 一维数组
            if($data['category'] == 2){
                $data['money'] = $data['money'] * MLM::getVIPDiscount(Auth::id());
            }
        }
        if(is_array($data)){
            foreach($data as &$v){
                $this->after($v);
            }
        }
        return $data;
    }
}